package com.simsuni.core;

import java.util.List;


public class SimScheduler {
	private SimModel model;
	private int limitTime;
	private SimClock clock;
	
	private enum Mode{Stop,Run,Pause};
	private Mode mode = Mode.Stop;
	
	private SimFutureEventList fel = new SimFutureEventList();
	
	public SimScheduler(SimModel model){
		this.model = model;
	}
	
	public void run(){
		mode = Mode.Run;
		
		while(mode == Mode.Run){
			if(!proceed() || limitTime < clock.getSimulationTime()){
				mode = Mode.Stop;
				break;
			}
		}
	}
	private boolean proceed(){
		
		SimEvent event = fel.dequeueImminentEvent();
		if(event==null){
			mode = Mode.Stop;
			return false;
		}
		SimSystemSnapShot snapShot = event.execute(clock);
		snapShot.report();
		fel.addEvent(generateFutureEvent(event));
		return true;
	}
	public void pause(){
		mode = Mode.Pause;
	}
	public void stop(){
		mode = Mode.Stop;
	}
	private List<SimEvent> generateFutureEvent(SimEvent event){
		
		return null;
	}
}
